import request from '@/config/axios'

import { BaseModel } from '@/api/common/baseModel'

export interface Model extends BaseModel {
  permission: string
  type: number
  parentId: string
  path: string
  icon: string
  component: string
  componentName?: string
  visible: boolean
  keepAlive: boolean
  alwaysShow?: boolean
  createTime: Date
}

// 查询列表
export const getPage = (params: PageParam) => {
  return request.get({ url: import.meta.env.VITE_BASE_ROLE + '/userCenter/auth/menu/page.json', params })
}

// 查询详情
export const getById = (id: string, level: number) => {
  return request.get({
    url: import.meta.env.VITE_BASE_ROLE + '/userCenter/auth/menu/getById.json?id=' + id + '&level=' + level
  })
}

// 修改
export const update = (data: Model) => {
  return request.put({ url: import.meta.env.VITE_BASE_ROLE + '/userCenter/auth/menu/update.json', data })
}

// 删除
export const del = (id: string, level: number) => {
  return request.delete({
    url: import.meta.env.VITE_BASE_ROLE + '/userCenter/auth/menu/del.json?id=' + id + '&level=' + level
  })
}

// 获取用户精简信息列表
export const getList = (param: any): Promise<Model[]> => {
  return request.get({ url: import.meta.env.VITE_BASE_ROLE + '/userCenter/auth/menu/arr.json', param })
}

// 导 出用户
export const exportMenu = (params) => {
  return request.download({ url: import.meta.env.VITE_BASE_ROLE + '/userCenter/auth/menu/export', params })
}

// 下载用户导入模板
export const importMenuTemplate = () => {
  return request.download({ url: import.meta.env.VITE_BASE_ROLE + '/userCenter/auth/menu/get-import-template' })
}

// 用户密码重 置
export const resetMenuPwd = (id: string, password: string) => {
  const data = {
    id,
    password
  }
  return request.put({ url: import.meta.env.VITE_BASE_ROLE + '/userCenter/auth/menu/update-password', data: data })
}

// 获取用户精简信息列表
export const getSimpleMenuList = (): Promise<Model[]> => {
  return request.get({ url: import.meta.env.VITE_BASE_ROLE + '/userCenter/auth/menu/arr.json' })
}
